How do you communicate between a Service Worker and the main thread? What is the role of BroadcastChannel vs postMessage here?
Service workers communicate via postMessage (to/from controlled pages) and BroadcastChannel (multiple contexts). Use navigator.serviceWorker.controller.postMessage() from page; worker responds via self.clients.matchAll().then(...).